package com.ceres.customer.dao;

import com.ceres.customer.pojo.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Component
public interface CustMenuMapper extends Mapper<Menu> {

    //模糊查询权限
    @Select("<script>select * from t_menu <if test=\"keyword!=null and keyword!=''\">where menu=#{keyword} and category=1</if></script>")
    List<Menu> findByKeyWord(@Param("keyword")String keyword);

    //查询所有菜单
    @Select("select * from t_menu where category=1 and type=1")
    List<Menu> findAllMenu();

    //查询所有权限
    @Select("select * from t_menu where category=1 and type=2")
    List<Menu> findAllPerm();

    //根据角色id查询菜单
    @Select("select * from t_menu where id in (select mid from t_role_menu where rid=#{id}) and type=1")
    List<Menu> findMenuByRoleId(int id);

    //根据角色id查询权限
    @Select("select * from t_menu where id in (select mid from t_role_menu where rid=#{id}) type=2")
    List<Menu> findPermByRoleId(int id);
}
